// 属性管理模块接口
import request from '@/utils/request'
import type { AttrResponseData } from './type'

enum API {
  // 查询一级分类接口
  CATEGORY_URL = '/admin/product/getCategory1',
  // 查询二级分类接口
  CATEGORY2_URL = '/admin/product/getCategory2/',
  // 查询三级分类接口
  CATEGORY3_URL = '/admin/product/getCategory3/',
  // 查询分类列表接口
  CATEGORY_LIST_URL = '/admin/product/attrInfoList/',
  // 保存/编辑属性接口
  CATEGORY_SAVE_URL = '/admin/product/saveAttrInfo',
  // 删除属性接口
  CATEGORY_DELETE_URL = '/admin/product/deleteAttr/'
}

// 获取一级分类方法
export const reqC1 = () => {
  return request.get<any, AttrResponseData>(API.CATEGORY_URL)
}

// 获取二级分类方法
export const reqC2 = (id: any) => {
  return request.get<any, AttrResponseData>(API.CATEGORY2_URL + id)
}

// 获取三级分类方法
export const reqC3 = (id: any) => {
  return request.get<any, AttrResponseData>(API.CATEGORY3_URL + id)
}

// 获取列表数据方法
export const reqCategoryList = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string
) => {
  return request.get<any, any>(
    API.CATEGORY_LIST_URL + `${category1Id}/${category2Id}/${category3Id}`
  )
}

// 保存or编辑方法
export const addOrUpdateAttrMethod = (data: any) => {
  if (data.id) {
    return request.put<any, AttrResponseData>(API.CATEGORY_SAVE_URL, data)
  } else {
    return request.post<any, AttrResponseData>(API.CATEGORY_SAVE_URL, data)
  }
}

// 删除品牌方法
export const delGategory = (id: any) => {
  return request.delete<any, any>(API.CATEGORY_DELETE_URL + `${id}`)
}
